package xx.iverson.file_manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xx.iverson.file_manager.entity.FileInfo;
import xx.iverson.file_manager.mapper.FileInfoMapper;
import xx.iverson.file_manager.service.FileInfoService;

import java.util.List;


/**
 * xx.iverson.file_manager.service.impl.FileInfoServiceImpl
 * 描述：
 * on 2025/9/18-上午9:09
 *
 * @author weijx
 */

@Service
public class FileInfoServiceImpl implements FileInfoService {


    @Autowired
    private FileInfoMapper fileInfoMapper;

    @Override
    public List<FileInfo> getAllFiles() {
        return fileInfoMapper.selectAllFilesWithCategory();
    }

    @Override
    public FileInfo getFileById(Integer id) {
        return fileInfoMapper.selectFileById(id);
    }

    @Override
    public List<FileInfo> getFilesByCategoryId(Integer categoryId) {
        return fileInfoMapper.selectFilesByCategoryId(categoryId);
    }

    @Override
    public List<FileInfo> getFilesByLevel1Id(Integer level1Id) {
        return fileInfoMapper.selectFilesByLevel1Id(level1Id);
    }

    @Override
    public List<FileInfo> getFilesByLevel2Id(Integer level2Id) {
        return fileInfoMapper.selectFilesByLevel2Id(level2Id);
    }

    @Override
    @Transactional
    public boolean addFile(FileInfo fileInfo) {
        int result = fileInfoMapper.insertFile(fileInfo);
        return result > 0;
    }

    @Override
    @Transactional
    public boolean updateFile(FileInfo fileInfo) {
        int result = fileInfoMapper.updateFile(fileInfo);
        return result > 0;
    }

    @Override
    @Transactional
    public boolean deleteFile(Integer id) {
        int result = fileInfoMapper.deleteFile(id);
        return result > 0;
    }

    @Override
    @Transactional
    public void incrementDownloadCount(Integer id) {
        fileInfoMapper.incrementDownloadCount(id);
    }

    @Override
    public List<FileInfo> searchFilesByName(String name) {
        return fileInfoMapper.searchFilesByName(name);
    }

    @Override
    public List<FileInfo> searchFilesByCategoryAndName(Integer categoryId, String name) {
        return fileInfoMapper.searchFilesByCategoryAndName(categoryId, name);
    }

    @Override
    public List<FileInfo> searchFilesByLevel1AndName(Integer level1Id, String name) {
        return fileInfoMapper.searchFilesByLevel1AndName(level1Id, name);
    }
}
